package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.ChargingStandards;
import com.hs.service.ChargingStandardsService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("ChargingStandardsController")
public class ChargingStandardsController {
    @Autowired
    private ChargingStandardsService chargingStandardsService;
    @PostMapping
    public R addChargingStandards(@RequestBody ChargingStandards chargingStandards) {
        int i = chargingStandardsService.addChargingStandards(chargingStandards);
        if (i > 0) {
            return R.ok();
        }else{
            return R.fail("增加失败");
        }
    }
    @DeleteMapping("{id}")
    public R deleteChargingStandards(@PathVariable int id) {
        int i = chargingStandardsService.deleteChargingStandards(id);
        if (i > 0) {
            return R.ok();
        }else{
            return R.fail("删除失败");
        }
    }
    @PutMapping
    public R updateChargingStandards(@RequestBody ChargingStandards chargingStandards) {
        int i = chargingStandardsService.updateChargingStandards(chargingStandards);
        if (i > 0) {
            return R.ok();
        }else{
            return R.fail("修改失败");
        }
    }
    @GetMapping("{id}")
    public R getChargingStandardsById(@PathVariable int id) {
        ChargingStandards chargingStandardsById = chargingStandardsService.getChargingStandardsById(id);
        return R.ok(chargingStandardsById);
    }
    @GetMapping("page")
    public R getChargingStandardsByPage(@RequestParam(required = false,defaultValue = "1")int pageNum,@RequestParam(required = false,defaultValue = "5")int pageSize) {
        PageInfo<ChargingStandards> chargingStandardsByPage = chargingStandardsService.getChargingStandardsByPage(pageNum, pageSize);
        return R.ok(chargingStandardsByPage);
    }
    @GetMapping("consultantId")
    public R getChargingStandardsByConsultantId(int consultantId,
                                                @RequestParam(required = false,defaultValue = "1")int pageNum,
                                                @RequestParam(required = false,defaultValue = "5")int pageSize) {
        PageInfo<ChargingStandards> chargingStandardsByConsultantId = chargingStandardsService.getChargingStandardsByConsultantId(consultantId, pageNum, pageSize);
        return R.ok(chargingStandardsByConsultantId);
    }
}
